<template>
	<div class='messageSetWrap'>
        <ul >
            <li class="clearfix" v-for="(item, index) in listMessage" :key="index">
                <span class="fl">{{item.smsTypeDesc}}</span>
                <mt-switch v-model="item.status == 1 ? true:false" @change="turn(item)" class="fr"></mt-switch>  
            </li>
        </ul>
        <!-- <ul v-show="false">
            <li class="clearfix">
                <span class="fl">运输任务提醒</span>
                <mt-switch v-model="value5" @change="turn('value5')" class="fr"></mt-switch>  
            </li>
        </ul> -->
        <p>打开开关后可实时接收推送消息</p>
    </div>
</template>
<script type="text/ecmascript-6">
import ApiService from "@/services/API-servies";
import { Switch,MessageBox } from "mint-ui";
export default {
  data() {
    return {
      listMessage:[],
    };
  },
  mounted() {
    setTimeout(() => {
    if(this.$isBrower.isAndroid){

      }else if(this.$isBrower.isIos){
          this.setIosTitleType();
      }
    }, 0);
    this.load()
  },
  methods: {
    turn: function(val) {
        if(val.status == 1){
            val.status = 0;
        }else{
          val.status = 1;
        }
        let params = {
              smsType:val.smsType,
              status: val.status,
            }
        ApiService.message.setPush(params).then(res => {
          if(res.meta.retCode != '0'){
                MessageBox('提示', '操作失败');
                return ;
            }
        });
        console.log(val.status);
    },
    setIosTitleType(){
      let params = {
        isReturn: true,
        isSearch: false,
        isTitleSegment:false
      };
      this.$bridge.callhandler('needBarButton', params, (data) => {})
    },
    load(){
      var _parent = {
        companyType:this.$route.query.type
      }
       ApiService.message.setList(_parent).then(res => {
           var _data = res.data;
           for (var i = 0; i < _data.length ; i++) {
              var _obj = _data[i];
               this.listMessage.push(_obj);
           }
          
        });
    }
  },
  filters: {},
  components: {
    MtSwitch: Switch
  }
};
</script>
<style scoped lang="less" type="stylesheet/less">
@import "~common/less/variable";
.messageSetWrap {
  ul {
    background-color: #fff;
    li {
        padding: 10px 20px;
        border-bottom: 1px solid #ccc;
        &:last-child{
            border: none;
        }
        label,span{
            line-height: normal;
        }
        span{
            line-height: 72px;
            font-size: 24px;
        }
        label{
            padding-top: 4px;
            transform: scale(0.7);
        }
    }
  }
  p{
      text-align: right;
      padding-right: 20px;
      color: #999;
  }
}
</style>
